var mongoose = require('mongoose');
var Schema = mongoose.Schema;

/**
 * 
 * Data model for port records.
 * 
 * @class Port
 * @author jmanero
 * 
 * @requires mongoose
 * 
 * @constructor
 * 
 */
var Port = new Schema({
	/**
	 * Parent device
	 * 
	 * @memberOf Port
	 * @type Schema.ObjectId
	 */
	device : {
		type : Schema.ObjectId,
		ref : 'Device'
	},
	/**
	 * Port name on parent device
	 * 
	 * @memberOf Port
	 * @type String
	 */
	name : {
		type : String
	},
	/**
	 * Local system ID for port
	 * 
	 * @memberOf Port
	 * @type String
	 */
	id : {
		type : String,
		unique : true
	},
	/**
	 * Last known value of port
	 * 
	 * @memberOf Port
	 * @type String
	 */
	value : {
		type : String
	},
	/**
	 * Data-type of port
	 * 
	 * @memberOf Port
	 * @type String
	 */
	type : {
		type : String,
		enum : [ 'String', 'Boolean', 'Number' ]
	},
	/**
	 * Directionality of port on device
	 * 
	 * @memberOf Port
	 * @type String
	 */
	direction : {
		type : String,
		enum : [ 'Input', 'Output', 'Bidirectional' ]
	},
	/**
	 * Meta-information: role of port
	 * 
	 * @memberOf Port
	 * @type String
	 */
	description : {
		type : String
	}
});

/**
 * Compound unique index of parent device and remote port name
 * 
 * @mamberOf Port
 * @type index
 * @static
 */
Port.index({
	device : 1,
	name : 1
}, {
	unique : true
});

/**
 * Fire off any one-time tasks after Port is defined
 * 
 * @memberOf Device
 * @static
 * 
 */
Port.statics.startup = function() {
	
};

model.Port = connection.model('Port', Port);
